<template>
	<view class="content" >

		<view v-if="show_main" class="main" >

			<view v-for="(item,index) in list" :key="index" @click="goPage" :data-uri="'/pages/business-details/business-details?id='+item.opportunity_id+'&classify_id='+item.classify_id" class="bgf m20 pr f30 p20" style="border-radius: 4px;">
				
				<view @click.stop="cancelCollect" :data-id="item.id" :data-index="index" class="pa" style="right: 10rpx;top:10rpx;">
					<u-icon name="a-shoucang1" custom-prefix="qxl-icon" color="#f60" size="50"></u-icon>
				</view>
				<view class="f30 b mb10">{{item.title}}</view>
				<view class="list disfr-lr">
					<!--<view class="disf" style="width: 300rpx;">
						<view style="width: 46rpx;height: 46rpx;overflow: hidden;border-radius:4px;flex-shrink: 0;">
							<u-image width="48rpx" height="48rpx" :src="item.head_pic">
								<template v-slot:error>
									<image src="/static/image/default-user.png" style="width:48rpx;height: 48rpx;"></image>
								</template>
							</u-image>
						</view>
						<view class="ml10 toell pr" style="top:3rpx;">{{item.nickname}}</view>
					</view>-->
					<view class="col999">{{item.add_time_str}}</view>
				</view>
				
				<view class="p20 mt20" style="background: #f4f4f4;border-radius: 6px;min-height: 100rpx;">
					{{item.content}}
				</view>
				<view class="disfr-lr mt10 col999">
					<view class="mt5" style="color:#2979ff">{{item.classify_str}}</view>
					<view class="disf">
						<view class="pr" style="top:8rpx;right: 30rpx;">{{item.area}}</view>
						<view>
							<u-icon name="eye-fill" size="44" style="position: relative;top:5rpx;"></u-icon>{{item.page_view}}
						</view>
					</view>
				</view>
			</view>
			
            <view v-if="list.length <= 0 && not_load" style="text-align: center;margin-top: 40%;">
				<view><u-icon name="wuneirong-copy" custom-prefix="qxl-icon" color="#999999" size="100"></u-icon></view>
				<view class="f32 col999 mt20">什么都木有哦</view>
			</view>
			
		</view>
		
		<pageload :page_load="page_load" :next_page="next_page" :list="list" /><!--分页加载状态-->
	   <loading :loading="not_load"/><!--加载状态-->
	   <u-no-network tips="哎呀，网络信号丢失"></u-no-network><!--检测网络-->
	</view>
</template>

<script setup>
import { onLoad, onShow, onHide, onReachBottom,onPullDownRefresh } from '@dcloudio/uni-app';
import { ref } from 'vue';	
const show_main=ref(false);
const page_load=ref(false);
const not_load=ref(false);
const next_page=ref('');
const list=ref([]);
//取消收藏
const cancelCollect=(e)=>{
	uni.$utils.showModal('确认取消收藏？',1,async()=>{
		not_load.value=false;
		let id=e.currentTarget.dataset.id;
		let index=e.currentTarget.dataset.index;
		let ret=await uni.$get('appapi-member-delcollect',{id:id});
		not_load.value=true;
		if(ret.error_code != 0){
			uni.$utils.showToast(ret.info);
			return;
		}
		loadPage({},false);
	});
	
};
//页面加载时
onLoad(async (options)=>{
    loadPage({},false);
});
const connected=(res)=>{
	
};
//页面显示时执行
onShow(()=>{
	
});
//页面隐藏时执行
onHide(()=>{
	
});

/**
 * 加载接口数据
 * @param {Object} options  参数,对像数组
 * @param {Object} isPage   是否加载大于1页
 */
const loadPage=async (options,isPage)=>{
	console.log('loadPage get');
	not_load.value=false;
	let ret = await uni.$get('appapi-member-collect',options);
	if(ret.error_code != 0){
		uni.$utils.showToast(ret.info);
		return;
	}
    page_load.value=false;
	show_main.value=true;
	not_load.value=true;
	next_page.value=ret.data.next_page;
	let tempString='';
	for(let i in ret.data.list){
		tempString=ret.data.list[i].content;
		tempString=tempString.replace(/\\n\\r/g,'');
		ret.data.list[i].content=uni.$utils.substr(tempString,52,'');
	}
	if(isPage) list.value=[...list.value,...ret.data.list];
	else list.value=ret.data.list;
	//console.log(list.value);
};
onPullDownRefresh(()=>{
	//console.log('onPullDownRefresh');
	//not_load.value=false;
	setTimeout(()=>{
		loadPage({},false);
		uni.stopPullDownRefresh();
	}, 1000);
});
//上拉触底加载分页
onReachBottom(()=>{
	if (!next_page.value) return;
	if (page_load.value) return;
	page_load.value=true;
	setTimeout(()=>{
	  loadPage(next_page.value, true); 
	},2000);
});
/**
 * 模板属性跳转页面
 * @param {Object} e
 */
function goPage(event){
	//topDropDownShow.value=false;
	//console.log(111111);
	uni.$utils.dataSetPage(event);
};
</script>

<style  lang="scss">
	page {
		
	}
.fnow{color:#2979ff;}
</style>
